import java.sql.SQLException;

import javax.jws.WebService;

@WebService(targetNamespace="http://localhost:63081/saveInDB")
public class SaveInDBService {

	public String saveOrders(String projectID, String materialName, String materialAmount, String materialUnit, String materialPrice)
	{
		String out = "Saved in DB";
		
		DAO dao = new DAO();
		double amount = Double.parseDouble(materialAmount);
		double price = Double.parseDouble(materialPrice);
		
		try {
			dao.addMaterial(materialName, amount, materialUnit, price, projectID);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			out = "Unable to save data in DB";
		}

		return out;
	}

	public String saveDeliveries(String projectID, String materialName, String materialAmount, String materialPrice)
	{
		String out = "Delivery data saved in DB";
		DAO dao = new DAO();
		
		double deliveredAmount = Double.parseDouble(materialAmount);
		double deliveredPrice = Double.parseDouble(materialPrice);
		
		try {
			dao.saveDeliveries(projectID, materialName, deliveredAmount, deliveredPrice);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			out = "Unable to save data in DB";
		}
		
		return out;
	}
}
